/*
 * 文件名称: ResponseData.java
 * 版权信息: Copyright 2005-2012 SKY-MOBI Inc. All right reserved.
 * ----------------------------------------------------------------------------------------------
 * 修改历史:
 * ----------------------------------------------------------------------------------------------
 * 修改原因: 新增
 * 修改人员: allen.hu
 * 修改日期: 2012-8-24
 * 修改内容: 
 */
package org.bigmouth.framework.response;

import com.googlecode.jsonplugin.JSONException;
import com.googlecode.jsonplugin.JSONUtil;

/**
 * 响应对象。
 * 
 * @author allen.hu / 2012-8-24
 */
public class ResponseData {

    public final static int SUCCEED = 200;

    public final static int FAILED = -1;
    
    public final static int TIME_OUT = -999;

    /**
     * 获得一个返回标准格式的JSON对象。
     * 
     * @param statusCode 返回状态码
     * @param message 返回消息
     * @return
     * @throws JSONException 
     */
    @SuppressWarnings("static-access")
    public static String getResult(int statusCode, String message) throws JSONException {
        ResponseObject obj = getResponseData(statusCode, message, null);
        JSONUtil util = new JSONUtil();
        return util.serialize(obj);
    }
    
    @SuppressWarnings("static-access")
    public static String getResult(int statusCode, String message, Object data) throws JSONException {
        ResponseObject obj = getResponseData(statusCode, message, data);
        JSONUtil util = new JSONUtil();
        return util.serialize(obj);
    }

    private static ResponseObject getResponseData(int statusCode, String message, Object data) {
        ResponseObject obj = new ResponseObject();
        obj.setResultCode(statusCode);
        obj.setResultMessage(message);
        obj.setResultData(data);
        return obj;
    }
    
}
